<?php

class ProjectController extends Controller {

    public function actionView() {
        try {
            $slug = isset($_GET['id']) ? $_GET['id'] : '';
            if ($slug !== '') {
                $model = Project::model()->findByAttributes(array(
                    'slug' => $slug
                        ));
                $this->render('view', array(
                    'model' => $model,
                ));
            }
        } catch (Exception $e) {
            Yii::log("Invalid request. Please do not repeat this request again.");
            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
        }
    }

    public function actionIndex() {
        try {
            $criteria = new CDbCriteria();
            $criteria->order = 't.created_date desc';
            $project = Project::model()->findAll($criteria);
            $this->render('index', array(
                'project' => $project
            ));
        } catch (Exception $e) {
            Yii::log("Invalid request. Please do not repeat this request again.");
            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
        }
    }

    public function loadModel($id) {
        try {
            $model = Project::model()->findByPk($id);
            if ($model === null)
                throw new CHttpException(404, 'The requested page does not exist.');
            return $model;
        } catch (Exception $e) {
            Yii::log("Invalid request. Please do not repeat this request again.");
            throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
        }
    }

}

?>
